package com.cskaoyan._05servlet_cart;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Macro_Ray
 * @since 2024/5/2 上午11:06
 */


@WebServlet(value = "/index", loadOnStartup = 1)
public class HomeIndexServlet extends HttpServlet {
    @Override
    public void init() throws ServletException {
        List<Product> productList = new ArrayList<>();
        productList.add(new Product(1, "问届M5", "入门款suv智驾车"));
        productList.add(new Product(2, "问届M7", "高级suv智驾车"));
        productList.add(new Product(3, "小米Su7", "年轻人第一辆帕拉梅拉"));
        productList.add(new Product(4, "极氪001", "围攻小米猎装车"));
//        getServletConfig().setAttribute("productList", productList);

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 我们自己创建几个商品。用来模拟从数据库中检索出的商品信息
        resp.setContentType("text/html;charset=utf-8");
//        List<Product> productList = (List<Product>) getServletConfig().getAttribute("productList");

//        for (Product product : productList) {
//            resp.getWriter().println("<div><a href=''>" + req.getContextPath() + "item?id=" + product.getId() +
//            "'>" + product.getName() + "</a></div>");
//        }
    }


}
